package com.ruoyi.btlfbreed.service.impl;

import java.util.List;

import com.ruoyi.btlfbreed.domain.TbChickenOutRegistry;
import com.ruoyi.btlfbreed.domain.TbChickens;
import com.ruoyi.btlfbreed.mapper.TbChickensMapper;
import com.ruoyi.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.btlfbreed.mapper.TbChickenDeathRecordsMapper;
import com.ruoyi.btlfbreed.domain.TbChickenDeathRecords;
import com.ruoyi.btlfbreed.service.ITbChickenDeathRecordsService;
import org.springframework.transaction.annotation.Transactional;

/**
 * 肉鸡死亡登记Service业务层处理
 * 
 * @author codeman
 * @date 2024-05-07
 */
@Service
public class TbChickenDeathRecordsServiceImpl implements ITbChickenDeathRecordsService 
{
    @Autowired
    private TbChickenDeathRecordsMapper tbChickenDeathRecordsMapper;
    @Autowired
    private TbChickensMapper tbChickensMapper;
    /**
     * 查询肉鸡死亡登记
     * 
     * @param id 肉鸡死亡登记主键
     * @return 肉鸡死亡登记
     */
    @Override
    public TbChickenDeathRecords selectTbChickenDeathRecordsById(Long id)
    {
        return tbChickenDeathRecordsMapper.selectTbChickenDeathRecordsById(id);
    }

    /**
     * 查询肉鸡死亡登记列表
     * 
     * @param tbChickenDeathRecords 肉鸡死亡登记
     * @return 肉鸡死亡登记
     */
    @Override
    public List<TbChickenDeathRecords> selectTbChickenDeathRecordsList(TbChickenDeathRecords tbChickenDeathRecords)
    {
        return tbChickenDeathRecordsMapper.selectTbChickenDeathRecordsList(tbChickenDeathRecords);
    }

    /**
     * 新增肉鸡死亡登记
     * 
     * @param tbChickenDeathRecords 肉鸡死亡登记
     * @return 结果
     */
    @Transactional
    @Override
    public int insertTbChickenDeathRecords(TbChickenDeathRecords tbChickenDeathRecords)
    {
        tbChickenDeathRecords.setCreateTime(DateUtils.getNowDate());
        TbChickens tbChickens=new TbChickens();
        tbChickens.setHealthStatus("2");
        tbChickens.setChickenId(tbChickenDeathRecords.getChickenId());
        tbChickensMapper.updateTbChickens(tbChickens);
        return tbChickenDeathRecordsMapper.insertTbChickenDeathRecords(tbChickenDeathRecords);
    }

    /**
     * 修改肉鸡死亡登记
     * 
     * @param tbChickenDeathRecords 肉鸡死亡登记
     * @return 结果
     */
    @Override
    public int updateTbChickenDeathRecords(TbChickenDeathRecords tbChickenDeathRecords)
    {
        tbChickenDeathRecords.setUpdateTime(DateUtils.getNowDate());
        return tbChickenDeathRecordsMapper.updateTbChickenDeathRecords(tbChickenDeathRecords);
    }

    /**
     * 批量删除肉鸡死亡登记
     * 
     * @param ids 需要删除的肉鸡死亡登记主键
     * @return 结果
     */
    @Override
    public int deleteTbChickenDeathRecordsByIds(Long[] ids)
    {
        return tbChickenDeathRecordsMapper.deleteTbChickenDeathRecordsByIds(ids);
    }

    /**
     * 删除肉鸡死亡登记信息
     * 
     * @param id 肉鸡死亡登记主键
     * @return 结果
     */
    @Transactional
    @Override
    public int deleteTbChickenDeathRecordsById(Long id)
    {
        TbChickenDeathRecords tbChickenDeathRecords=new TbChickenDeathRecords();
        tbChickenDeathRecords= tbChickenDeathRecordsMapper.selectTbChickenDeathRecordsById(id);

        TbChickens tbChickens=new TbChickens();
        tbChickens.setHealthStatus("0");
        tbChickens.setChickenId(tbChickenDeathRecords.getChickenId());
        tbChickensMapper.updateTbChickens(tbChickens);
        return tbChickenDeathRecordsMapper.deleteTbChickenDeathRecordsById(id);
    }
}
